package com.dys.testcomparable09;

/**
 * @className: com.dys.testcomparable09.Student
 * @description: com.dys.testcomparable09
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/08/08 下午8:16
 */
public class Student implements Comparable<Student> {
    private String name;
    private int age;
    private double height;

    public Student(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }

    /**
     * 内部比较器
     *
     * @return 比较后的结果
     */
    @Override
    public int compareTo(Student o) {
        // 1.按照年龄比较
        // return this.getAge() - o.getAge();
        // 2.按照身高进行比较
        // return ((Double)(this.getHeight())).compareTo((Double)(o.getHeight()));
        // 3.按照名字进行比较
        return this.getName().compareTo(o.getName());
    }
}
